require("../../res/www.a9a.cn.js");
var t = getApp();
Page({
  data: {
    src: "",
    width: 200,
    height: 250,
    max_width: 400,
    max_height: 500,
    disable_rotate: !1,
    disable_ratio: !0,
    limit_move: !0,
  },
  onLoad: function (t) {
    (this.cropper = this.selectComponent("#image-cropper")),
      this.setData({ src: t.imgSrc }),
      t.imgSrc || this.cropper.upload();
  },
  cropperload: function (t) {},
  loadimage: function (t) {
    wx.hideLoading(), this.cropper.imgReset();
  },
  clickcut: function (t) {
    wx.previewImage({ current: t.detail.url, urls: [t.detail.url] });
  },
  upload: function () {
    var t = this;
    wx.chooseMedia({
      count: 1,
      mediaType: ["image"],
      sizeType: ["original", "compressed"],
      sourceType: ["album", "camera"],
      success: function (e) {
        wx.showLoading({ title: "加载中" });
        var a = e.tempFiles[0].tempFilePath;
        t.cropper.imgReset(), t.setData({ src: a });
      },
    });
  },
  setWidth: function (t) {
    this.setData({ width: t.detail.value < 10 ? 10 : t.detail.value }),
      this.setData({ cut_left: this.cropper.data.cut_left });
  },
  setHeight: function (t) {
    this.setData({ height: t.detail.value < 10 ? 10 : t.detail.value }),
      this.setData({ cut_top: this.cropper.data.cut_top });
  },
  switchChangeDisableRatio: function (t) {
    this.setData({ disable_ratio: t.detail.value });
  },
  setCutTop: function (t) {
    this.setData({ cut_top: t.detail.value }),
      this.setData({ cut_top: this.cropper.data.cut_top });
  },
  setCutLeft: function (t) {
    this.setData({ cut_left: t.detail.value }),
      this.setData({ cut_left: this.cropper.data.cut_left });
  },
  switchChangeDisableRotate: function (t) {
    t.detail.value
      ? this.setData({ disable_rotate: t.detail.value })
      : this.setData({ limit_move: !1, disable_rotate: t.detail.value });
  },
  switchChangeLimitMove: function (t) {
    return !1;
  },
  switchChangeDisableWidth: function (t) {
    return !1;
  },
  switchChangeDisableHeight: function (t) {
    return !1;
  },
  submit: function () {
    this.cropper.getImg(function (e) {
      (t.globalData.U.photo_s = e.url), wx.navigateBack({ delta: -1 });
      var a = wx.getStorageSync("COOK_U");
      wx.uploadFile({
        url: t.WWW + "/api/wxxcx/reg.php",
        filePath: e.url,
        name: "pic",
        formData: { submitok: "photo_s_update", openid: a.openid },
        success: function (t) {},
      });
    });
  },
  rotateL: function (t) {
    this.cropper.setAngle((this.cropper.data.angle -= 90));
  },
  rotateR: function (t) {
    this.cropper.setAngle((this.cropper.data.angle += 90));
  },
  top: function () {
    var t = this;
    this.data.top = setInterval(function () {
      t.cropper.setTransform({ y: -3 });
    }, 1e3 / 60);
  },
  bottom: function () {
    var t = this;
    this.data.bottom = setInterval(function () {
      t.cropper.setTransform({ y: 3 });
    }, 1e3 / 60);
  },
  left: function () {
    var t = this;
    this.data.left = setInterval(function () {
      t.cropper.setTransform({ x: -3 });
    }, 1e3 / 60);
  },
  right: function () {
    var t = this;
    this.data.right = setInterval(function () {
      t.cropper.setTransform({ x: 3 });
    }, 1e3 / 60);
  },
  narrow: function () {
    var t = this;
    this.data.narrow = setInterval(function () {
      t.cropper.setTransform({ scale: -0.02 });
    }, 1e3 / 60);
  },
  enlarge: function () {
    var t = this;
    this.data.enlarge = setInterval(function () {
      t.cropper.setTransform({ scale: 0.02 });
    }, 1e3 / 60);
  },
  end: function (t) {
    clearInterval(this.data[t.currentTarget.dataset.type]);
  },
});
